<template>
    <div>
        <hs-breadcrumb :breadcrumb="breadcrumb"></hs-breadcrumb>
        <Card :bordered="false" :style="{marginBottom:'10px'}">
            <div class="hs-screen-row">
                <Input v-model="params.orderCode" placeholder="提现订单编号" clearable style="width: 200px"/>
            </div>
            <div class="hs-screen-row">
                <Input v-model="params.username" placeholder="账号" clearable style="width: 200px"/>
            </div>
            <div class="hs-screen-row">
                <Input v-model="params.nickName" placeholder="昵称" clearable style="width: 200px"/>
            </div>
            <div class="hs-screen-row">
                <Select v-model="params.orderState" placeholder="状态" clearable style="width:200px">
                    <Option value="">全部</Option>
                    <Option value="1">待审核</Option>
                    <Option value="2">审核通过</Option>
                    <Option value="3">审核拒绝</Option>
                </Select>
            </div>
            <div class="hs-screen-row">
                <DatePicker @on-change="changeDate" v-model="dateInit" type="daterange" :editable="false"
                            separator=" ~ " split-panels transfer
                            placeholder="创建时间" style="width: 200px"></DatePicker>
            </div>
            <div class="hs-screen-row">
                <Button type="primary" @click="findList">查询</Button>
            </div>
            <div class="hs-screen-row">
                <Button @click="resetScreen">重置</Button>
            </div>
        </Card>

        <Card :bordered="false" :style="{marginBottom:'10px'}">
            <!--标题-->
            <div slot="title">
                <div class="hs-screen-box">
                    <div>提现列表</div>
                    <div>
                        <ButtonGroup>
                            <Button @click="findList">
                                <Icon type="md-refresh" size="15"/>
                            </Button>
                            <!--                            <Button @click="showAdminOpe(2)">新增提现</Button>-->
                        </ButtonGroup>
                    </div>
                </div>
            </div>

            <div style="margin-bottom: 10px">
                <Button type="dashed" @click="batchOpe">导出订单</Button>
            </div>
            <!--表格数据-->
            <Table :columns="columns" :data="data" size="small" :stripe="true" :loading="isTableLoading"
                   @on-select="selectTable" @on-select-cancel="selectCancelTable" @on-select-all="selectAllTable"
                   @on-select-all-cancel="selectAllCancelTable">

                <template slot-scope="{ row, index }" slot="remark">
                    <span>{{row.remark?row.remark:'-'}}</span>
                </template>
                <template slot-scope="{ row, index }" slot="orderTitle">
                    <span>{{row.orderTitle?row.orderTitle:'-'}}</span>
                </template>

                <template slot-scope="{ row, index }" slot="orderState">
                    <span v-if="row.orderState == 1">待审核</span>
                    <span v-if="row.orderState == 2">审核通过</span>
                    <span v-if="row.orderState == 3">审核拒绝</span>
                </template>

                <template slot-scope="{ row }" slot="action">
                    <Button type="success" size="small" style="margin-right: 5px" @click="showAdminOpe(1, row)">查看
                    </Button>
                    <template v-if="row.orderState == 1">
                        <Button type="primary" size="small" style="margin-right: 5px" @click="showAdminOpe(3, row)">审核
                        </Button>
                    </template>

                </template>
            </Table>
            <!--分页-->
            <div class="hs-page">
                <Page :total="total" show-sizer show-total transfer @on-change="changePage"
                      @on-page-size-change="changePageSize"/>
            </div>
        </Card>

        <!--显示模态框-->
        <admin-ope ref="adminOpe" @changeData="findList"></admin-ope>
    </div>
</template>

<script>
    import hsBreadcrumb from '@/components/hs-breadcrumb';
    import adminOpe from './components/withdrawal-ope';

    export default {
        name: "recharge",
        data() {
            return {
                total: 0,
                dateInit: '',
                isTableLoading: false,
                // 选中数据
                selectData: [],
                // 参数
                params: {
                    page: 1,
                    rows: 10,
                    orderCode: '',
                    username: '',
                    nickName: '',
                    orderState: '',
                    startTime: '',
                    endTime: '',
                    orderIds: ''
                },
                // 表格列
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        type: 'index',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: 'ID',
                        minWidth: 120,
                        key: 'orderId'
                    },
                    {
                        title: '订单编号',
                        minWidth: 180,
                        key: 'orderCode'
                    },
                    {
                        title: '提现金额',
                        minWidth: 120,
                        key: 'totalAmount'
                    },
                    {
                        title: '实际到账金额',
                        minWidth: 120,
                        key: 'realAmount'
                    },
                    {
                        title: '手续费',
                        minWidth: 120,
                        key: 'poundage'
                    },
                    {
                        title: '用户余额',
                        minWidth: 120,
                        key: 'userBalance'
                    },
                    {
                        title: '用户备注',
                        minWidth: 180,
                        slot: 'orderTitle',
                        ellipsis: true
                    },
                    {
                        title: '账号',
                        minWidth: 120,
                        key: 'username'
                    },
                    {
                        title: '昵称',
                        minWidth: 120,
                        key: 'nickName'
                    },
                    {
                        title: '审核备注',
                        minWidth: 180,
                        slot: 'remark',
                        ellipsis: true
                    },
                    {
                        title: '订单状态',
                        slot: 'orderState',
                        align: 'center',
                        width: 120
                    },
                    {
                        title: '创建时间',
                        key: 'createTime',
                        width: 150
                    },
                    {
                        title: '操作',
                        slot: 'action',
                        width: 180,
                        align: 'center'
                    }
                ],
                // 表格数据
                data: [],
                // 面包屑
                breadcrumb: [
                    {name: '首页', url: '', icon: 'ios-home-outline', size: 18},
                    {name: '系统管理', url: '', icon: '', size: 0},
                    {name: '提现列表', url: '', icon: '', size: 0}
                ]
            }
        },
        created() {
            // 提现-列表查询
            this.findList();
        },
        methods: {
            // 提现-列表查询
            findList() {
                this.isTableLoading = true;
                this.axios.post('/userWithdraw/findList', this.params).then(res => {
                    
                    this.isTableLoading = false;
                    if (res.status == 200) {
                        this.total = res.data.total;
                        this.data = res.data.rows;
                    }
                    if (res.status == 500) {
                        this.$Notice.error({
                            title: '服务器内部错误',
                            desc: '查询提现列表接口报错',
                            duration: 0
                        });
                    }
                })
            },
            // 导出订单Excel
            exportExcel() {
                this.$Spin.show();
                this.axios.post('/userWithdraw/exportExcel', this.params, {
                    responseType: 'arraybuffer'
                }).then(res => {
                    
                    setTimeout(() => {
                        this.$Spin.hide();
                    }, 300);
                    // 
                    let blob = new Blob([res], {type: 'Files'});
                    let csvUrl = URL.createObjectURL(blob);
                    let link = document.createElement('a');
                    link.href = csvUrl;
                    // 下载xlsx文件
                    link.download = "商品订单列表.xls";
                    link.click();
                    if (res.status == 201) {
                        // this.$Message.error(res.msg);
                        this.$Notice.error({
                            title: '删除订单失败',
                            desc: res.msg
                        });
                    }
                    if (res.status == 500) {
                        this.$Notice.error({
                            title: '服务器内部错误',
                            desc: '删除订单接口报错',
                            duration: 0
                        });
                    }
                })
            },
            // 显示操作模态框
            showAdminOpe(type, row) {
                /**
                 * type判断
                 * 1.查看 2.新增 3.编辑
                 */
                this.$refs.adminOpe.show(type, row);
            },
            // 日期条件赋值
            changeDate(e) {
                this.params.startTime = e[0];
                this.params.endTime = e[1];
            },
            // 重置筛选条件
            resetScreen() {
                this.params.orderCode = '';
                this.params.username = '';
                this.params.nickName = '';
                this.params.orderState = '';
                this.params.endTime = '';
                this.params.startTime = '';
                this.dateInit = '';
            },
            // 改变页数
            changePage(e) {
                this.params.page = e;
                this.findList();
            },
            // 改变页容量
            changePageSize(e) {
                this.params.rows = e;
                this.findList();
            },
            // 在多选模式下有效，选中某一项时触发
            selectTable(selection, row) {
                this.selectData = selection;
            },
            // 在多选模式下有效，取消选中某一项时触发
            selectCancelTable(selection, row) {
                this.selectData = selection;
            },
            // 在多选模式下有效，点击全选时触发
            selectAllTable(selection) {
                this.selectData = selection;
            },
            // 在多选模式下有效，点击取消全选时触发
            selectAllCancelTable(selection) {
                this.selectData = selection;
            },
            batchOpe() {

                let arr = [];
                if (this.selectData.length) {
                    this.selectData.forEach(v => {
                        arr.push(v.orderId)
                    })
                }
                this.params.orderIds = arr.join(',');

                if (this.params.orderIds) {
                    this.$Modal.confirm({
                        title: `确定导出选中的订单？`,
                        onOk: () => {
                            // this.$Message.info('您点击了确定.');
                            this.exportExcel();
                        },
                        onCancel: () => {
                            this.$Message.info('您点击了取消.');
                        }
                    });
                } else {
                    this.$Modal.confirm({
                        title: `确定导出订单？`,
                        onOk: () => {
                            // this.$Message.info('您点击了确定.');
                            this.exportExcel();
                        },
                        onCancel: () => {
                            this.$Message.info('您点击了取消.');
                        }
                    });
                }
            }
        },
        components: {
            hsBreadcrumb,
            adminOpe
        }
    }
</script>

<style scoped>

</style>